function TreeNode(val, left, right) {
    this.val = (val === undefined ? 0 : val);
    this.left = (left === undefined ? null : left);
    this.right = (right === undefined ? null : right);
}

let preorder = [3, 9, 20, 15, 7], inorder = [9, 3, 15, 20, 7]
var buildTree = function (preorder, inorder) {
    const root = new TreeNode(preorder[0])
    const head = inorder.findIndex(item => item === 3)
    const left = preorder.slice(1, head + 1)
    const right = preorder.slice(head + 1, preorder.length)

};
console.log(buildTree(preorder, inorder));
